<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/common/layui/css/layui.css"/>
    <link rel="stylesheet" href="/css/global.css"/>
    <style>
        #groupTransfer {
            width: 80%;
            height: 70%;
            padding: 0 13%;
        }

        .layui-transfer.layui-form.layui-border-box {
            width: auto;
            height: auto;
        }

        .tools {
            margin: 5% 0 0 38%;
        }

    </style>
</head>
<body>
<div id="groupTransfer"></div>
<div class="tools">
    <button class="layui-btn layui-btn-normal" lay-transferactive="submit">分配</button>
    <button class="layui-btn layui-btn-primary" lay-transferactive="cancel">取消</button>
</div>
</body>
<script src="../../common/layui/layui.js"></script>
<script src="../../js/global.js"></script>
<script>
    layui.use(['transfer', 'layer', 'util'], function () {
        let $ = layui.$
            , transfer = layui.transfer
            , layer = layui.layer
            , util = layui.util;

        let searchParams = parseSearchParams(window.location.pathname);
        let param = {"id": searchParams.id, "teamLeaderId": searchParams.teamLeaderId};
        ajax("/admin/team/unAllocated/".concat(param.id), "GET", "", (res) => {
            if (res.code === 0) {
                let data = res.data;
                let memberIds = [];
                for (let item of data) {
                    if (!isEmpty(item.teamId)) {
                        memberIds.push(item.id);
                    }
                }
                transfer.render({
                    id: "group",
                    elem: "#groupTransfer",
                    title: ["未分组学生", "当前小组成员"],
                    showSearch: true,
                    data: data,
                    value: memberIds,
                    parseData: (res) => {
                        return {
                            "value": res.id //数据值
                            , "title": res.name //数据标题
                        }
                    }
                });
            }
        });


        //批量办法定事件
        util.event('lay-TransferActive', {
            submit: (othis) => {
                let getData = transfer.getData('group');
                let allotMemberIds = [];
                for (let item of getData) {
                    allotMemberIds.push(item.value);
                }
                let jsonStr = JSON.stringify(allotMemberIds);
                let params = jsonStr.substring(1, jsonStr.length - 1);
                ajax("/admin/team/allotMember?ids=".concat(params), "GET", param, (res) => {
                    layer.msg(res.msg);
                });
            }, cancel: () => {
                let index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                // window.parent.location.reload();
                parent.layui.table.reload("groupTable");
            }
        });
    });
</script>
</html>